﻿CREATE TABLE [dbo].[AngajatiSporuri] (
    [IdTipSpor]           INT             NOT NULL,
    [IdPersoana]          INT             NOT NULL,
    [DeLaData]            DATETIME        NOT NULL,
    [IdPersoanaSpor]      INT             IDENTITY (1, 1) NOT NULL,
    [PanaLaData]          DATETIME        NULL,
    [Valoare]             DECIMAL (18, 2) CONSTRAINT [DF_PersoaneSporuri_Valoare] DEFAULT ((0)) NOT NULL,
    [Procent]             DECIMAL (6, 2)  CONSTRAINT [DF_PersoaneSporuri_Procent] DEFAULT ((0)) NOT NULL,
    [ValoarePreaviz]      DECIMAL (18, 2) CONSTRAINT [DF_PersoaneSporuri_ValoarePreaviz] DEFAULT ((0)) NOT NULL,
    [IDAngajatSalarizare] INT             NULL,
    [Luna]                SMALLINT        DEFAULT ((0)) NOT NULL,
    [Anul]                SMALLINT        DEFAULT ((0)) NOT NULL,
    [CodUnitate]          SMALLINT        DEFAULT ((0)) NOT NULL,
    [ValoareCalculata]    AS              ([dbo].[resuma_CalculValoareSpor]([IDPersoanaSpor])),
    [FormatSpor]          AS              ([dbo].[resuma_GetSporFormat]([IDTipSpor])),
    [OrdineSpor]          AS              ([dbo].[resuma_GetSporOrder]([IDTipSpor])),
    CONSTRAINT [PK_Sporuri] PRIMARY KEY CLUSTERED ([IdPersoanaSpor] ASC),
    CONSTRAINT [FK_AngajatiSporuri_AngajatiSalarizare] FOREIGN KEY ([IDAngajatSalarizare]) REFERENCES [dbo].[AngajatiSalarizare] ([IDAngajatSalarizare]),
    CONSTRAINT [FK_AngajatiSporuri_Unitati] FOREIGN KEY ([CodUnitate]) REFERENCES [dbo].[Unitati] ([CodUnitate]),
    CONSTRAINT [FK_Sporuri_Persoane] FOREIGN KEY ([IdPersoana]) REFERENCES [dbo].[Persoane] ([IdPersoana])
);

